#!/usr/bin/env bash

if [[ ${rvm_leave_gem_alone:-0} -eq 0 ]]
then
  function gem
  {
    \typeset result
    (
      \typeset rvmrc
      rvm_rvmrc_files=("/etc/rvmrc" "$HOME/.rvmrc")
      if [[ -n "${rvm_prefix:-}" ]] && ! [[ "$HOME/.rvmrc" -ef "${rvm_prefix}/.rvmrc" ]]
         then rvm_rvmrc_files+=( "${rvm_prefix}/.rvmrc" )
      fi

      for rvmrc in "${rvm_rvmrc_files[@]}"
      do [[ -s "${rvmrc}" ]] && source "${rvmrc}" || true
      done
      unset rvm_rvmrc_files
      command gem "$@"
    ) || result=$?
    hash -r
    return ${result:-0}
  }
fi
